<template>
     <div class="components-container">
         <div class="header-form">
            <!-- <div class="layui-inline">
                <label class="layui-form-label">使用状态</label>
                <div class="layui-inline">
                  <el-radio-group v-model="selectData.IchstatusEqual" @change="getData">
                    <el-radio-button :label="all">全部</el-radio-button>
                    <el-radio-button v-for="item in usetype" :key="item.Value" :label="item.Value" class="radio">{{item.Text}}</el-radio-button>
                  </el-radio-group>
                </div>
            </div> -->
            <div class="layui-inline">
                <label class="layui-form-label" >逝者姓名</label>
                <div class="layui-input-inline">
                    <el-input v-model="selectData.TmmregNameLike" ></el-input>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" >家属姓名</label>
                <div class="layui-input-inline">
                    <el-input v-model="selectData.TmmhandlerNameLike" ></el-input>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" >墓穴位置</label>
                <div class="layui-input-inline">
                    <el-input v-model="selectData.TmmpostionLike" ></el-input>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" >购墓日期</label>
                <!-- RegdateGreaterAndEquals
                RegdateLessAndEquals -->
                <el-date-picker v-date v-model="selectData.TmmpurchaseDateGreaterAndEquals" type="date" placeholder="选择日期范围" >
                </el-date-picker>
                <el-date-picker v-date v-model="selectData.TmmpurchaseDateLessAndEquals" type="date" placeholder="选择日期范围">
                </el-date-picker>
            </div>
            <!-- <div class="layui-inline">
                  <label class="layui-form-label" >开始日期</label>
                  <el-date-picker v-date v-model="selectData.IchbegdateGreaterAndEquals" type="date" placeholder="大于等于该日期" style="width: 200px">
                  </el-date-picker>
                  <el-date-picker v-date v-model="selectData.IchbegdateLessAndEquals" type="date" placeholder="小于等于该日期" style="width: 200px">
                  </el-date-picker>
            </div> -->
            <el-button type="primary" :disabled="downloadLoading" @click="btnSearch" :loading="this.$store.state.isloading" >搜索</el-button>
            <el-button :disabled="this.$store.state.isloading || downloadLoading"  @click="btnRepeat">重置</el-button>
        </div>
        <div>
          <ul class="toolList"> 
            <li v-if="btnShow(item.BTNVALUE)" v-for="(item, index) in $store.state.btnListCommon" @click="operate(item.BTNVALUE)">
              <el-button type="primary" :disabled="$store.state.isloading" :value="item.BTNSHOWNAME" v-text="item.BTNSHOWNAME"></el-button>
            </li>
            <li>
            <el-button type="primary" :disabled="this.$store.state.isloading"  @click="exportExcel" style="margin-left:20px;margin-bottom:-10px;">导出Excel</el-button>
            </li>
          </ul>
        </div>
        <dataTable :btnList="btnList" :headList="headList" :dataList="dataList" :isIndex="true" :pageOrder="pageOrder" :hiddenPageOrder="false" :height="height" @pageChange="pageChange" @selectRow="selectRow"></dataTable>
        <!-- <cemeteryData ref="simpleReg"  @refreshData="getData"></cemeteryData> -->
        <printmodal ref="printPdf"></printmodal>
        <cemeteryData ref="simpleReg" :orderType="order" @refreshData="getData"></cemeteryData>
     </div>
</template>

<script>
import dataTable from "@/components/Table/DataTable";
import cemeteryData from "./tombsUseMain";

import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import printmodal from "@/components/Pdf/Print";
import { PRINT } from "@/components/Pdf/PDF.js";
// import cresimplereg from "../businessHall/cresimplereg";
const INFO = "详情";
const EXPORT = "导出";
const ADD = '新增';
const CRDETAILS = "火化登记详情";
const MODIFY = "修改";
const DELETE = '删除';
const SPELL = '拼穴'
export default {
  name: "iceuseSearch",
  mixins: [manage],
  data() {
    return {
      all: null,
      selectData: {
        // TmxnoLike: null,
        // TmxnameLike: null,
        // TmxtmbidLike: null,
        // TmxcodnameEquals: null,

        TmmpurchaseDateGreaterAndEquals: null,  
        TmmpurchaseDateLessAndEquals: null, 
        TmmregNameLike: null,  
        TmmhandlerNameLike: null,  
        TmmpostionLike: null,  

        // IchbegdateGreaterAndEquals: null,
        // IchbegdateLessAndEquals: null
      },
      usetype: [],
      activeName: "results",
      height: "620",
      downloadLoading:false,
      btnList: [
        {
          BTNSHOWNAME: '拼穴',
          BTNVALUE: '拼穴'
        }
      ]
    };
  },
  methods: {
    exportExcel() {
      var startTime;
      var endTime;
      if(this.selectData.TmmpurchaseDateGreaterAndEquals){
        startTime = this.selectData.TmmpurchaseDateGreaterAndEquals.toLocaleDateString();
      }else{
        startTime = '空';
      }
      if(this.selectData.TmmpurchaseDateLessAndEquals){
        endTime = this.selectData.TmmpurchaseDateLessAndEquals.toLocaleDateString();
      }else{
        endTime = '空';
      }
      var header = '墓地资料' + '(' + startTime + '--' + endTime + ')';
       if (this.dataList.length === 0){
          this.$message.error("无导出数据！");
          return;
      }
      this.downloadLoading = true;
      require.ensure([], () => {
        const { export_json_to_excel } = require("@/vendor/Export2Excel");
        export_json_to_excel(this.headList, this.dataList, header);
        this.downloadLoading = false;
      });
    },
    //功能操作
    operate(order) {
      this.order = order;
      switch (this.order) {
        case INFO:
          this.$refs.simpleReg.open(this.order, this.currentRow.TMMID);
          break;
        case EXPORT:
          this.$refs.printPdf.report(PRINT.PDFICEDISPATCHSEARCH,this.getDataC());
          break;
        case CRDETAILS:
          this.$refs.simpleReg.open('详情', this.currentRow.TMMID);
          break;
        case MODIFY:
          this.$refs.simpleReg.open('修改', this.currentRow.TMMID);
          break;
        case ADD:
          this.$refs.simpleReg.open('新增');
          break;
        case SPELL:
          this.$refs.simpleReg.open(SPELL, this.currentRow.TMMPOSTION);
          break;
        case DELETE:
          this.$refs.simpleReg.open('删除', this.currentRow.TMMID);
        default:
      }
    },
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetTombsColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    getDataC(){
      let Data = JSON.parse(JSON.stringify(this.selectData));
    //   if (!this.selectData.TmxnoLike) {
    //     Data.TmxnoLike = null;
    //   };
    //   if (!this.selectData.TmxnameLike) {
    //     Data.TmxnameLike = null;
    //   };
    //   if (!this.selectData.TmxtmbidLike) {
    //     Data.TmxtmbidLike = null;
    //   };
      // Data.IchbegdateGreaterAndEquals = formatDate(
      //   Data.IchbegdateGreaterAndEquals,
      //   "yyyyMMdd"
      // );
      // Data.IchbegdateLessAndEquals = formatDate(
      //   Data.IchbegdateLessAndEquals,
      //   "yyyyMMdd"
      // );
      let data = {
        PageIndex: -1,
        PageSize: 0,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      return data;
    },
    getData() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      if(this.selectData.TmmpurchaseDateGreaterAndEquals){
        Data.TmmpurchaseDateGreaterAndEquals =  formatDate(Data.TmmpurchaseDateGreaterAndEquals, "yyyyMMdd");
      }
      if(this.selectData.TmmpurchaseDateLessAndEquals){
        Data.TmmpurchaseDateLessAndEquals =  formatDate(Data.TmmpurchaseDateLessAndEquals, "yyyyMMdd");
      }
      let data = {   
        PageIndex: -1,
        PageSize: 0,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      apiBase.DoService(data, apiBase.getApiAdress().Tombs.Query, res => {
        this.dataList = res.data.content.OutData;
        this.activeName = "results";
        this.pageOrder.totalNum = res.data.content.RecordCount;
      });
    },
    //获取业务状态
    // getIchStatus() {
    //   let data = {};
    //   apiBase.DoService(
    //     data,
    //     apiBase.getApiAdress().IceUse.GetIchStatus,
    //     res => {
    //       this.usetype = res.data.content;
    //     }
    //   );
    // },
    //获取所属墓型
    getCemeteryData() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Code.GetTombtype,
        res => {
          this.usetype = res.data.content;
        }
      );
    },
    btnShow(btn){
      switch (btn) {
          case '导出':
            return true;
            break;
          case '新增':
            return true;
            break;
          case '修改':
            return true;
            break;
          case '删除':
            return true;
            break;
          case '详情':
            return true;
            break;
          default: return false;
        }
    },
    //查询条件重置
    btnRepeat() {
      this.selectData = {
        TmxnoLike: null,
        TmxnameLike: null,
        TmxtmbidLike: null,
        TmxcodnameEquals: null,

        TmmpurchaseDateGreaterAndEquals: null,  
        TmmpurchaseDateLessAndEquals: null, 
        TmmregNameLike: null,  
        TmmhandlerNameLike: null,  
        TmmpostionLike: null,  
        // IchbegdateGreaterAndEquals: null,
        // IchbegdateLessAndEquals: null
      };
      // this.selectData.IchbegdateGreaterAndEquals = new Date(946662995000);
      // this.selectData.IchbegdateGreaterAndEquals.setDate(1);
      // this.selectData.IchbegdateLessAndEquals = new Date();
      // var day = new Date();
      // var year = day.getFullYear();
      // var month = day.getMonth()+1;
      // var d = new Date(year, month, 0);
      // var dat = d.getDate();
      // this.selectData.IchbegdateLessAndEquals.setDate(dat);
      this.getData();
    }
  },
  mounted() {
    // console.log(this.all);
    // this.selectData.IchstatusEqual = "A";
    // console.log(4141);
  },
  components: {
    dataTable,
    cemeteryData,
    // cresimplereg,
    printmodal
  },
  created() {
    // this.selectData.IchbegdateGreaterAndEquals = new Date(946662995000);
    // this.selectData.IchbegdateGreaterAndEquals.setDate(1);
    // this.selectData.IchbegdateLessAndEquals = new Date();
    // this.selectData.IchstatusEqual = "A";
    var day = new Date();
    var year = day.getFullYear();
    var month = day.getMonth()+1;
    var d = new Date(year, month, 0);
    var dat = d.getDate();
    // this.selectData.IchbegdateLessAndEquals.setDate(dat);
    this.getColumns();//获取headerlist
    this.getData();//获取数据
    this.getCemeteryData();//获取所属墓型
    // this.btnRepeat();
  }
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
</style>

